﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="ContractDetail.aspx.cs" Inherits="QLHD.ContractDetail" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <script language="javascript" type="text/javascript" src="/Scripts/gridcolumn-control.js"></script>
    <%--<script language="javascript" type="text/javascript" src="/Scripts/ContractManagement.js"></script>--%>
    <script language="javascript" type="text/javascript" src="/Scripts/ContractDetail.js"></script>
    <script language="javascript" type="text/javascript" src="/Scripts/ajaxupload.js"></script>
    <script language="javascript" type="text/javascript" src="/Scripts/ContractGrid.js"></script>
    <script>
        mnggridid = "phulucgrid";
        contractpermistion = parseInt('<%=userpermistion %>');
        MaHD = '<%=Request.Params["MaHD"] %>';
    </script>
    <script type="text/javascript">
        $(function () {
            //Function to upload file.
            if (contractpermistion >= 3) {
                new AjaxUpload('#uploadFile', {
                    action: 'FileUploadHandler.upload',
                    name: 'upload',
                    onComplete: function (file, response) {
                        if (response == "accessdenied") {
                            $('#uploadStatus').html("access denied");
                        } else if (response == "error") {
                            $('#uploadStatus').html("Lỗi");
                        }
                        else if (response == "success") {
                            $('<div class="doc-item left"><img src="/styles/images/Close-icon.png" style="width:20px;height:20px" class="delete"/><label>' + file + '</label><div class="clear"></div></div>').appendTo('#fileList');
                            $('#uploadStatus').html("Tải lên hoàn tất.");
                        } else {
                            $('#uploadStatus').html("Tài liệu này đã tồn tại.");
                        }
                    },
                    onSubmit: function (file, ext) {
                        if (!(ext && /^(txt|doc|docx|xls|xlsx|pdf)$/i.test(ext))) {
                            alert('Định dạng file không cho phép.');
                            return false;
                        }
                        $('#uploadStatus').html("Đang tải lên...");
                    }
                });
                //Function to delete uploaded file in server.
                $('img.delete').live("click", function () { $('#uploadStatus').html("Đang xóa..."); deleteFile($(this)); });
                $('label.download').unbind("click");
                $('label.download').click(function () { download(this); });
            } else {
                $("#uploadFile").remove();
                $("#fileList .doc-item .delete").remove();
            }
        });
        function deleteFile(objfile) {
            if (confirm("Bạn có chắc chắn muốn xóa " + $.trim(objfile.parent().children("label").text()) + " không?")) {
                $.ajax({ url: 'FileUploadHandler.upload?del=' + $.trim(objfile.parent().children("label").text()), success: function () { objfile.parent().hide(); } });
                $('#uploadStatus').html("Đã xóa");
            } else {
                $('#uploadStatus').html("");
            }
        }
        function download(objfile) {
            window.open('FileUploadHandler.upload?dl=' + $.trim($(objfile).text()));
        }
    </script>
    
    <script type="text/x-kendo-template" id="template">        
        <div class="toolbar">
        <% if(!string.IsNullOrEmpty(userpermistion) &&  int.Parse(userpermistion)>=3) {%>
            <div class="function-button">
                <a class="k-button k-button-icontext k-grid-add"><span class="k-icon k-add"></span>Thêm mới XNKL</a>
                <a class="k-button k-button-icontext k-grid-save-changes"><span class="k-icon k-update"></span>Lưu thay đổi</a>
                <a class="k-button k-button-icontext k-grid-cancel-changes"><span class="k-icon k-cancel"></span>Hủy thay đổi</a>
            </div>
            <%} %>
        </div>
         <kendo:grid-column-command>
            <kendo:grid-column-commandItem name="Delete" text="Xóa" click="DeleteXNKL"/>
        </kendo:grid-column-command>
    </script>
    <script type="text/x-kendo-template" id="ckptemplate">        
        <div class="toolbar">
        <% if(!string.IsNullOrEmpty(userpermistion) &&  int.Parse(userpermistion)>=3) {%>
            <div class="function-button">
                <a class="k-button k-button-icontext k-grid-addd" href="javascript:void(0);" onclick="AddEditKCP(null);"><span class="k-icon k-add"></span>Thêm mới KCP</a>
            </div>
            <%} %>
        </div>
         <kendo:grid-column-command>
            <kendo:grid-column-commandItem name="Delete" text="Xóa" click="DeleteKCP"/>
            <kendo:grid-column-commandItem name="Detail" text="Chi tiết" click="ViewDetail"/>
        </kendo:grid-column-command>
    </script>
    <script type="text/x-kendo-template" id="contractmngtemplate">    
        <div class="toolbar">
         <% if(!string.IsNullOrEmpty(userpermistion) && int.Parse(userpermistion)>=3) {%>
            <div class="function-button">
                <a class="k-button k-button-icontext k-grid-add"><span class="k-icon k-add"></span>Thêm phụ lục</a>
                <a class="k-button k-button-icontext k-grid-save-changes"><span class="k-icon k-update"></span>Lưu thay đổi</a>
                <a class="k-button k-button-icontext k-grid-cancel-changes"><span class="k-icon k-cancel"></span>Hủy thay đổi</a>
            </div>
            <%} %>
        </div>
        <kendo:grid-column-command>
            <kendo:grid-column-commandItem name="destroy" text="Xóa"/>
            <kendo:grid-column-commandItem name="Detail" text="Chi tiết" click="ViewDetail"/>
        </kendo:grid-column-command>
    </script>

    <script type="text/x-kendo-template" id="thuengoaitemlate">    
        <div class="toolbar">
         <% if(!string.IsNullOrEmpty(userpermistion) && int.Parse(userpermistion)>=3) {%>
            <div class="function-button">
                <a class="k-button k-button-icontext k-grid-add"><span class="k-icon k-add"></span>Thêm thuê ngoài</a>
                <a class="k-button k-button-icontext k-grid-save-changes"><span class="k-icon k-update"></span>Lưu thay đổi</a>
                <a class="k-button k-button-icontext k-grid-cancel-changes"><span class="k-icon k-cancel"></span>Hủy thay đổi</a>
            </div>
            <%} %>
        </div>
        <kendo:grid-column-command>
            <kendo:grid-column-commandItem name="destroy" text="Xóa"/>
            <kendo:grid-column-commandItem name="Detail" text="Chi tiết" click="ViewDetail"/>
        </kendo:grid-column-command>
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="SidebarContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <script>
        $().ready(function () {
            $("#thuengoaigrid").InitialContractGrid({ contractpermistion: contractpermistion, ParentID: MaHD, contractmngtemplate: $("#thuengoaitemlate"), contracttype: 1 });
            $("#phulucgrid").InitialContractGrid({ contractpermistion: contractpermistion, ParentID: MaHD, contractmngtemplate: $("#contractmngtemplate"), contracttype: 0 });
            $('label.download').click(function () { download(this); });
        });
    </script>
    <div id="msg">
    </div>
    <div class="contract-detail-first">
        <table class="table-detail" cellspacing="5" border="1">
            <caption class="caption">
                Chi tiết Hợp đồng</caption>
            <tr>
                <td>
                    Tên công trình:
                </td>
                <td>
                    <asp:Literal runat="server" ID="ltTencontrinh"></asp:Literal>
                </td>
            </tr>
            <tr>
                <td>
                    Đối tác:
                </td>
                <td>
                    <asp:Literal runat="server" ID="ltDoitac"></asp:Literal>
                </td>
            </tr>
            <tr>
                <td>
                    Số hợp đồng:
                </td>
                <td>
                    <asp:Literal runat="server" ID="ltSohopdong"></asp:Literal>
                </td>
            </tr>
            <tr>
                <td>
                    Giá trị:
                </td>
                <td>
                    <asp:Literal runat="server" ID="ltGiatri"></asp:Literal>&nbsp;VNĐ
                </td>
            </tr>
            <tr>
                <td>
                    Thời gian nộp báo cáo:
                </td>
                <td>
                    <asp:Literal runat="server" ID="ltThoigianthuchien"></asp:Literal>
                </td>
            </tr>
            <tr>
                <td>
                    Giá trị thanh lý:
                </td>
                <td>
                    <asp:Literal runat="server" ID="ltGiatrithanhly"></asp:Literal>
                </td>
            </tr>
            <tr>
                <td>
                    Ngày thanh lý:
                </td>
                <td>
                    <asp:Literal runat="server" ID="ltNgaythanhly"></asp:Literal>
                </td>
            </tr>
            <tr>
                <td>
                    Ngày tạo:
                </td>
                <td>
                    <asp:Literal runat="server" ID="ltNgaytao"></asp:Literal>
                </td>
            </tr>
            <tr>
                <td>
                    Phòng:
                </td>
                <td>
                    <asp:Literal runat="server" ID="ltPhong"></asp:Literal>
                </td>
            </tr>
            <tr>
                <td>
                    Thời gian cảnh báo:
                </td>
                <td>
                    <asp:Literal runat="server" ID="ltThoigiancanhbao"></asp:Literal>
                    &nbsp;ngày
                </td>
            </tr>
            <tr>
                <td>
                    Ghi chú:
                </td>
                <td>
                    <asp:Literal runat="server" ID="ltGhichu"></asp:Literal>
                    &nbsp;ngày
                </td>
            </tr>
            <tr>
                <td >
                    Tài liệu:
                </td>
                <td>
                    <div id="fileList">
                        <asp:Repeater runat="server" ID="rptailieu">
                            <ItemTemplate>
                                <div class="doc-item left">
                                    <img src="/styles/images/Close-icon.png" class="delete" alt="xóa tài liệu" title="xóa tài liệu" /><label
                                        title="tải xuống" class="download">
                                        <%# System.IO.Path.GetFileName(Eval("FilePath").ToString()) %></label><div class="clear">
                                        </div>
                                </div>
                            </ItemTemplate>
                        </asp:Repeater>
                    </div>
                    <div class="clear">
                    </div>
                </td>
            </tr>
            <tr>
            <td></td>
                <td>
                    <div>
                        <input style="float: left; margin-right: 10px;" type="button" id="uploadFile" value="Thêm tài liệu" />
                        <div id="uploadStatus" style="color: red; float: left;">
                        </div>
                        <div class="clear">
                        </div>
                    </div>
                </td>
            </tr>
        </table>
        <div style="margin-top: 15px;">
            <div class="caption">
                Phụ lục
            </div>
            <div id="divPhuluc" class="k-content">
                <div id="phulucgrid">
                </div>
            </div>
        </div>
        <div style="margin-top: 15px;">
                <div class="caption">
                    XNKL
                </div>
                <div id="example" class="k-content">
                    <div id="xnklgrid">
                    </div>
                </div>
            </div>
        <div style="margin-top: 15px;" runat="server" id="divthuengoai">
            <div class="caption">
                Thuê ngoài
            </div>
            <div id="div1" class="k-content">
                <div id="thuengoaigrid">
                </div>
            </div>
        </div>
    </div>
    <div id="window" style="display:none;"></div>
    <div class="contract-detail-first" style=" display:none;">
        <div style="border-width: 0 1px 0 0;" class="contract-info1">
            <div style="display:none;">
            <div class="caption">
                    Khoán chi phí
                </div>
                <div id="divKCP" class="k-content">
                    <div id="kcpgrid">
                    </div>
                </div>
            </div>
            
        </div>
        <%--<div class="contract-history">
            <div class="caption">
                Thay đổi
            </div>
            <asp:Repeater runat="server" ID="rpHistory">
                <HeaderTemplate>
                    <ul class="contract-history">
                </HeaderTemplate>
                <ItemTemplate>
                    <li><%#Eval("Text") %></li>
                </ItemTemplate>
                <FooterTemplate>
                    </ul>
                </FooterTemplate>
            </asp:Repeater>
        </div>--%>
        <div class="clear">
        </div>
    </div>
    
    <div class="contract-detail-middle">
    </div>
</asp:Content>
